﻿package mortal.game.view.autoArena.view
{
    import com.greensock.layout.*;
    import com.mui.controls.*;
    import extend.language.*;
    import fl.data.*;
    import flash.display.*;
    import flash.events.*;
    import mortal.common.*;
    import mortal.common.global.*;
    import mortal.component.window.*;
    import mortal.game.cache.*;
    import mortal.game.mvc.*;
    import mortal.game.resource.*;
    import mortal.game.view.autoArena.renderer.*;
    import mortal.game.view.common.*;
    import mortal.game.view.common.pageSelect.*;
    import mortal.mvc.core.*;
    import mortal.mvc.interfaces.*;

    public class AutoArenaRankWin extends BaseWindow
    {
        private var _rankList:GTileList;
        private var _pageSelecter:PageSelecter;
        private var _btnRankDetail:GButton;
        private static var _instance:AutoArenaRankWin;

        public function AutoArenaRankWin(param1:ILayer = null)
        {
            super(param1);
            setSize(489, 531);
            title = Language.getString(40879);
            return;
        }// end function

        override protected function createDisposedChildrenImpl() : void
        {
            super.createDisposedChildrenImpl();
            this.pushUIToDisposeVec(UIFactory.bg(10, 37, 471, 488, this));
            this.pushUIToDisposeVec(UIFactory.bg(11, (37 + 1), 471, 23, this, ImagesConst.RegionTitleBg));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40880), 19 + 2, 45 - 6, 35, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40881), 121, 45 - 6, 35, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40882), 270, 45 - 6, 35, 20, this));
            this.pushUIToDisposeVec(UIFactory.gTextField(Language.getString(40883), 379, 45 - 6, 65, 20, this));
            this._rankList = UIFactory.tileList(10, 37 + 23, 471, 457, this);
            this._rankList.columnWidth = 471;
            this._rankList.rowHeight = 43;
            this._rankList.horizontalGap = 0;
            this._rankList.verticalGap = 0;
            this._rankList.setStyle("skin", new Bitmap());
            this._rankList.setStyle("cellRenderer", AutoArenaRankListRenderer);
            var _loc_1:* = GlobalStyle.textFormatBai;
            _loc_1.align = AlignMode.CENTER;
            this._pageSelecter = UIFactory.pageSelecter(176, 494 + 2, this, PageSelecter.CompleteMode);
            this._pageSelecter.setbgStlye(ImagesConst.InputBg, _loc_1);
            this._pageSelecter.pageTextBoxSize = 50;
            this._pageSelecter.maxPage = 10;
            this._pageSelecter.configEventListener(Event.CHANGE, this.onPageChange);
            this._btnRankDetail = UIFactory.gButton(Language.getString(41503), 356, 498, 131, 22, this.contentTopOf3DSprite, "GreenLinkButton");
            this._btnRankDetail.configEventListener(MouseEvent.CLICK, this.onClickDetailPlay);
            this.reqRankInfo();
            this.addListeners();
            return;
        }// end function

        private function reqRankInfo() : void
        {
            GameProxy.autoArena.getAutoArenaToplist(this._pageSelecter.currentPage);
            return;
        }// end function

        private function addListeners() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.AutoArenaGetRankInfo, this.onGetRankInfoHandler);
            return;
        }// end function

        private function removeListeners() : void
        {
            NetDispatcher.addCmdListener(ServerCommand.AutoArenaGetRankInfo, this.onGetRankInfoHandler);
            return;
        }// end function

        private function onGetRankInfoHandler(param1:Object) : void
        {
            this.updateInfoList();
            return;
        }// end function

        private function updateInfoList() : void
        {
            var _loc_7:Object = null;
            var _loc_1:* = (this._pageSelecter.currentPage - 1) * 10;
            var _loc_2:* = this._pageSelecter.currentPage * 10;
            var _loc_3:* = Cache.instance.autoArena.autoArenaRankArr;
            var _loc_4:* = _loc_3.slice(_loc_1, _loc_2);
            var _loc_5:* = new DataProvider();
            var _loc_6:int = 0;
            while (_loc_6 < _loc_3.length)
            {
                
                _loc_7 = {};
                _loc_7["rank"] = _loc_1 + _loc_6 + 1;
                _loc_7["player"] = _loc_3[_loc_6];
                _loc_5.addItem(_loc_7);
                _loc_6++;
            }
            this._rankList.dataProvider = _loc_5;
            this._rankList.drawNow();
            return;
        }// end function

        private function onPageChange(event:Event) : void
        {
            this.reqRankInfo();
            return;
        }// end function

        private function onClickDetailPlay(event:MouseEvent) : void
        {
            AutoArenaRankRuleWin.instance.show();
            return;
        }// end function

        override protected function disposeImpl(param1:Boolean = true) : void
        {
            super.disposeImpl();
            this._rankList.dispose();
            this._rankList = null;
            this._pageSelecter.dispose();
            this._pageSelecter = null;
            this._btnRankDetail.dispose();
            this._btnRankDetail = null;
            this.removeListeners();
            return;
        }// end function

        public static function get instance() : AutoArenaRankWin
        {
            if (_instance == null)
            {
                _instance = new AutoArenaRankWin;
            }
            return _instance;
        }// end function

    }
}
